package net.sh.dpinfrastructure.http;

import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * http响应
 * 
 * @version 1.0
 * @since JDK1.7
 * @author shaohui
 * @company 上海朝阳永续信息技术有限公司
 * @copyright (c) 2015 SunTime Co'Ltd Inc. All rights reserved.
 * @date 2015年9月16日 下午4:14:01
 */
public class DPHttpResponse implements Serializable {

    private static final long serialVersionUID = -8341986776803127973L;

    private int code;

    private long length;

    private byte[] content;
    
    private final Map<String, String> headers = new HashMap<>();

    public DPHttpResponse() {
        
    }
    
    public Map<String, String> getHeaders() {
        return headers;
    }

    public DPHttpResponse(int code, long length, byte[] content) {
        this.code = code;
        this.length = length;
        this.content = content;
    }
    
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public long getLength() {
        return length;
    }

    public void setLength(long length) {
        this.length = length;
    }

    public String getContentAsString(Charset charset) {
        if (charset == null) {
            charset = Charset.defaultCharset();
        }
        return new String(this.content, charset);
    }
    
    public String getContentAsString() {
        return new String(this.content, Charset.defaultCharset());
    }
    
    public byte[] getContent() {
        return this.content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

}
